<?php 
require_once 'sesi_login.php';
require_once 'konfigurasi.php';

fungsi('perkara');

define('PAGE', 'Perkara');
define('PAGE_ICO', 'icon-notes-2');
define('PAGE_URL', 'perkara.php');

koneksi_buka();
panggil_header();
?>

<!-- Content Area -->
<div id="da-content-area">
<div class="row-fluid">

<div class="span12">
	<div class="da-panel collapsible">
		<div class="da-panel-header">
			<span class="da-panel-title">
				<i class="icon-notes-2"></i> Data Perkara
			</span>
		</div>
		<?php if(LEVEL=="superadmin" || LEVEL=="sekretariat" || LEVEL=="penuntutan" ) { ?>
		<div class="da-panel-toolbar">
			<div class="btn-toolbar">
				<div class="btn-group">
					<a href="spdp.php" class="btn"><i class="icol-add"></i> Tambah SPDP</a>
				</div>
			</div>
		</div>
		<?php } ?>
		<div class="da-panel-content da-table-container">
			<table id="da-ex-datatable-numberpaging" class="da-table">
				<thead>
					<tr>
						<th>Tanggal</th>
						<th>Kode Perkara</th>
						<th>Tersangka</th>
						<th>Penyidik</th>
						<th></th>
					</tr>
				</thead>
				<tbody>
					<?php 
						if(LEVEL=="jaksa") {
							$jaksa_perkara = mysql_fetch_array(mysql_query("
								SELECT GROUP_CONCAT(\"'\",kd_perkara,\"'\") 
								FROM t_p16_jaksa WHERE kd_pegawai ='".ID_PEGAWAI."'"));
							
							if($jaksa_perkara[0]!="") {
								$batas = "WHERE a.kd_perkara IN (".$jaksa_perkara[0].")";
							} else {
								$batas = "WHERE a.kd_perkara IN ('')";
							}
						} else {
							$batas = "";
						}
						
						$q = mysql_query("
							SELECT a.kd_perkara, tgl_dimulai, nm_kesatuan, nm_lengkap
							FROM t_perkara a
							LEFT JOIN t_spdp b ON a.kd_perkara = b.kd_perkara
							LEFT JOIN r_kesatuan c ON b.kd_kesatuan = c.kd_kesatuan
							LEFT JOIN t_tersangka_spdp d ON a.kd_perkara = d.kd_perkara
							LEFT JOIN t_tersangka e ON d.kd_tersangka = e.kd_tersangka
							$batas GROUP BY a.kd_perkara
						");
						
						while($dt = mysql_fetch_array($q)) {
					?>
					<tr>
						<td><?php echo konversi_tanggal('d/m/Y',$dt['tgl_dimulai']) ?></td>
						<td><?php echo $dt['kd_perkara'] ?></td>
						<td><?php echo $dt['nm_lengkap'].jml_tersangka($dt['kd_perkara']) ?></td>
						<td><?php echo $dt['nm_kesatuan'] ?></td>
						<td>
							<a href="perkara.detail.php?kd=<?php echo $dt['kd_perkara'] ?>" rel="tooltip" data-placement="top" title="Detail"><i class="icol-magnifier"></i></a>
						</td>
					</tr>
					<?php } ?>
					
				</tbody>
			</table>
		</div>
	</div>
</div>

</div>
</div>

<?php
panggil_footer();
koneksi_tutup();
?>
